/**
 * Created by Elsa on 2017/9/5.
 */

layui.define(['jquery', 'layer','paging', 'code','form','element','upload'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        upload = layui.upload,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var lognum = getQueryString("rgstnum");

    paging.init({
        url: contextPath + "/project/ops/log/" + lognum, //地址
        elem: '#con', //内容容器
        type: 'GET',
        params: { //发送到服务端的参数

        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调
        },
    });

    $("body").on("click",".moress",function(){
        var logtime = $(this).data('id');
        tampdata = $(this).data('id');

        $.get('OperaDetailsLog.html', null, function(OperaDetailsLog) {
            layer.open({
                type: 1,
                title: '日志详情',
                content: OperaDetailsLog,
                area: ['auto', '600px'],
                maxmin: false,
                success:function (layero,index) {
                    layero.find("#closex").on("click",function () {
                        layer.closeAll();
                    });
                    layero.find("#close").on("click",function () {
                        layer.closeAll();
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/ops/log/info",
                        data: {"lognum": lognum, "logtime": logtime},
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {

                            if(data.logpicture1){
                                var logpicture1name = data.logpicture1.substring(data.logpicture1.lastIndexOf("/")+1,data.logpicture1.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture1name+'"><img src="'+contextPath+'/download?file='+data.logpicture1+'" class="layui-upload-img" id="img-'+logpicture1name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture1" href="'+contextPath+'/download?file='+data.logpicture1+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture2){
                                var logpicture2name = data.logpicture2.substring(data.logpicture2.lastIndexOf("/")+1,data.logpicture2.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture2name+'"><img src="'+contextPath+'/download?file='+data.logpicture2+'" class="layui-upload-img" id="img-'+logpicture2name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture2" href="'+contextPath+'/download?file='+data.logpicture2+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture3){
                                var logpicture3name = data.logpicture3.substring(data.logpicture3.lastIndexOf("/")+1,data.logpicture3.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture3name+'"><img src="'+contextPath+'/download?file='+data.logpicture3+'" class="layui-upload-img" id="img-'+logpicture3name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture3" href="'+contextPath+'/download?file='+data.logpicture3+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture4){
                                var logpicture4name = data.logpicture4.substring(data.logpicture4.lastIndexOf("/")+1,data.logpicture4.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture4name+'"><img src="'+contextPath+'/download?file='+data.logpicture4+'" class="layui-upload-img" id="img-'+logpicture4name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture4" href="'+contextPath+'/download?file='+data.logpicture4+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture5){
                                var logpicture5name = data.logpicture5.substring(data.logpicture5.lastIndexOf("/")+1,data.logpicture5.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture5name+'"><img src="'+contextPath+'/download?file='+data.logpicture5+'" class="layui-upload-img" id="img-'+logpicture5name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture5" href="'+contextPath+'/download?file='+data.logpicture5+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture6){
                                var logpicture6name = data.logpicture6.substring(data.logpicture6.lastIndexOf("/")+1,data.logpicture6.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture6name+'"><img src="'+contextPath+'/download?file='+data.logpicture6+'" class="layui-upload-img" id="img-'+logpicture6name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture6" href="'+contextPath+'/download?file='+data.logpicture6+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture7){
                                var logpicture7name = data.logpicture7.substring(data.logpicture7.lastIndexOf("/")+1,data.logpicture7.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture7name+'"><img src="'+contextPath+'/download?file='+data.logpicture7+'" class="layui-upload-img" id="img-'+logpicture7name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture7" href="'+contextPath+'/download?file='+data.logpicture7+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>');
                            }
                            if(data.logpicture8){
                                var logpicture8name = data.logpicture8.substring(data.logpicture8.lastIndexOf("/")+1,data.logpicture8.lastIndexOf("."));
                                $('#logpicturelist').append('<div style="display: inline-block" id="div-'+logpicture8name+'"><img src="'+contextPath+'/download?file='+data.logpicture8+'" class="layui-upload-img" id="img-'+logpicture8name+'"><p style="text-align: center;width: 110px"><a class="layui-btn layui-btn-normal" id="logpicture8" href="'+contextPath+'/download?file='+data.logpicture8+'" style="visibility: visible"><i class="fa fa-download"></i>下载</a></p></div>')
                            }
                            if(data.logvideo1){
                                var logvideo1name = data.logvideo1.substring(data.logvideo1.lastIndexOf("/")+1,data.logvideo1.lastIndexOf("."));
                                $('#logvideolist1').attr("href",contextPath+'/download?file='+data.logvideo1);
                                $('#logvideolist1name').html("&ensp;"+logvideo1name);
                                $('#logvideolist1').css("visibility",'visible');
                            }
                            if(data.logvideo2){
                                var logvideo2name = data.logvideo2.substring(data.logvideo2.lastIndexOf("/")+1,data.logvideo2.lastIndexOf("."));
                                $('#logvideolist2').attr("href",contextPath+'/download?file='+data.logvideo2);
                                $('#logvideolist2name').html("&ensp;"+logvideo2name);
                                $('#logvideolist2').css("visibility",'visible');
                            }

                            $('input[name="logname"]').attr("value",data.logname);
                            $('input[name="lognum"]').attr("value",data.lognum);
                            $('input[name="ycsname"]').attr("value",data.ycsname);
                            $('input[name="insptype"]').attr("value",data.insptype);
                            $('input[name="address"]').attr("value",data.address);
                            $('input[name="logtime"]').attr("value",data.logtime);
                            $('textarea[name="logcontent"]').val(data.logcontent);
                        },
                        error:function (e) {
                        }
                    });

                },
                yes: function(index) {
                    console.log(index);
                },
                full: function(elem) {
                    var win = window.top === window.self ? window : parent.window;
                    $(win).on('resize', function() {
                        var $this = $(this);
                        elem.width($this.width()).height($this.height()).css({
                            top: 0,
                            left: 0
                        });
                        elem.children('div.layui-layer-content').height($this.height() - 95);
                    });
                }
            });
            form.render();
        });
    });

    $('body').on('click', '#close', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });
    
    exports('OperaLogList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});